--
-- Author: ping.wang
-- Date: 2018-09-25 17:23:15
--
-- newCrystalPropRender
--

local ClassRef = app.mvc.createRenderClass(...)
local string_format = string.format
--data =
function ClassRef.createWithData(data, node)
    local sprite = ClassRef.extend(node or cc.CSLoader:createNode(Res.Tips_CrystalRender))
    if node == nil then
        ccui.Helper:doLayout(sprite)
    end
    sprite:init(data)
    return sprite
end
function ClassRef.create(node)
    return ClassRef.createWithData(nil, node)
end

--
function ClassRef:init(data)
    self.super.init(self, data)
    self:setContentSize( self._ui.Panel:getContentSize() )

    self._slotBg_1 = self._ui["Panel/bg_1"] -- 品质背景框
    self._slotBg_2 = self._ui["Panel/bg_2"] -- 镶嵌槽bg
    self._slotIcon = self._ui["Panel/icon"] -- 镶嵌的水晶icon
    self._slotAttrName = self._ui["Panel/data_tlt"] --水晶名
    self._slotAttrNum = self._ui["Panel/num"]

    self:refresh()
end

function ClassRef:refresh()
    if self._data then
        self:setVisible( true )
        local itemId = self._data
        if itemId and tonumber(itemId) > 0 then
            local itemInfo = GD:queryItemById(tonumber(itemId))
            local rockInfo = GD:queryRockById(tonumber(itemId))
            self._slotAttrName:setString(L(itemInfo.name))
            self._slotAttrNum:setString(string_format("+%s",rockInfo.leve))
            self._slotIcon:loadTexture(string_format("%s%s.png", Res.itemPath, itemInfo.icon))
            self._slotBg_2:setVisible(true)
            self._slotAttrNum:setVisible(true)
            self._slotIcon:setVisible(true)
            self._slotAttrName:setColor(cc.c3b( 255, 255, 255 ))
        else
            self._slotBg_2:setVisible(false)
            self._slotAttrNum:setVisible(false)
            self._slotIcon:setVisible(false)
            self._slotAttrName:setString(L("lua_code_text_439"))
            self._slotAttrName:setColor(cc.c3b( 155, 155, 155 ))
        end

    else
        self:setVisible( false )
    end
end

function ClassRef:onBtnClick(cb)
    self._onClick = cb
end

return ClassRef
